﻿using SketchUpAPI.NET.Enums;
using SketchUpAPI.NET.SketchUp.Exception;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace SketchUpAPI.NET.Objects
{
    /// <summary>
    /// 动态组件的属性
    /// </summary>
    /// <remarks>对 SketchUpAPI 中 SUDynamicComponentAttributeRef 的包装</remarks>
    public class DynamicComponentAttribute : ObjectBase
    {
        #region API 函数
        /// <summary>
        /// 获取属性名字
        /// </summary>
        /// <param name="attribute"></param>
        /// <param name="name"><see cref="StringRef"/></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUDynamicComponentAttributeGetName(IntPtr attribute, ref IntPtr name);

        /// <summary>
        /// 获取属性显示名字
        /// </summary>
        /// <param name="attribute"></param>
        /// <param name="display_name"><see cref="StringRef"/></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUDynamicComponentAttributeGetDisplayName(IntPtr attribute, ref IntPtr display_name);

        /// <summary>
        /// 获取属性是否可见
        /// </summary>
        /// <param name="attribute"></param>
        /// <param name="visible"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUDynamicComponentAttributeGetVisibility(IntPtr attribute, out bool visible);

        /// <summary>
        /// 获取属性显示值
        /// </summary>
        /// <param name="attribute"></param>
        /// <param name="display_value"><see cref="StringRef"/></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUDynamicComponentAttributeGetDisplayValue(IntPtr attribute, ref IntPtr display_value);
        #endregion

        /// <summary>
        /// 属性名字
        /// </summary>
        public string Name
        {
            get
            {
                StringRef s = StringRef.Empty;
                SketchUpExceptionHelper.ThrowSUResult(SUDynamicComponentAttributeGetName(Id, ref s.Id));
                return s.Dispose();
            }
        }

        /// <summary>
        /// 显示名字
        /// </summary>
        public string DisplayName
        {
            get
            {
                StringRef s = StringRef.Empty;
                SketchUpExceptionHelper.ThrowSUResult(SUDynamicComponentAttributeGetDisplayName(Id, ref s.Id));
                return s.Dispose();
            }
        }

        /// <summary>
        /// 显示值
        /// </summary>
        public string DisplayValue
        {
            get
            {
                StringRef s = StringRef.Empty;
                SketchUpExceptionHelper.ThrowSUResult(SUDynamicComponentAttributeGetDisplayValue(Id, ref s.Id));
                return s.Dispose();
            }
        }

        /// <summary>
        /// 是否可见
        /// </summary>
        public bool Visibility
        {
            get
            {
                SketchUpExceptionHelper.ThrowSUResult(SUDynamicComponentAttributeGetVisibility(Id, out bool v));
                return v;
            }
        }

        internal DynamicComponentAttribute(IntPtr id) => Id = id;
    }
}